package com.hzw.saas.service.chat.mapper;


import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.hzw.saas.service.chat.model.ChatEvent;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;


@Mapper
public interface ChatEventMapper extends BaseMapper<ChatEvent> {

    @Select("<script>SELECT\n" +
        "\ta.* \n" +
        "FROM\n" +
        "\ttb_chat_event AS a\n" +
        "\tRIGHT JOIN \n" +
        "\t( SELECT \n" +
        "\ttb_chat_event.target_group_id, \n" +
        "\tmax( tb_chat_event.milli_second ) AS max_time\n" +
        "\t FROM tb_chat_event WHERE \n" +
        "\t tb_chat_event.target_group_id IN <foreach item=\"groupId\" collection=\"groupIds\"  open=\"(\" separator=\",\" close=\")\"> #{groupId} </foreach> \n" +
        "\t GROUP BY tb_chat_event.target_group_id )\n" +
        "\t AS b \n" +
        "\t ON a.target_group_id = b.target_group_id \n" +
        "\tAND a.milli_second = b.max_time  group by a.target_group_id\n" +
        "ORDER BY\n" +
        "\ta.milli_second DESC LIMIT #{count},#{size} </script>")
    List<ChatEvent> findChatHistoryList(@Param("groupIds") List<String> groupIds,@Param("count") Long count,@Param("size") Long size);
}
